/**
 * 非常规工作日窗口
 */
Ext.namespace("Ext.ux.workholiday");

Ext.ux.workholiday.SpecialPeriodDetailWindow = Ext.extend(Ext.Window, {

	width: 600,
	height: 250,
	layout: 'fit',
	plain : true,
	modal: true,
	border: false,
	
	detailPanel: null,
	closeAction: 'hide',
	id: 'specialTimeDetailWindow',

	initComponent:function(){
		Ext.ux.workholiday.SpecialPeriodDetailWindow.superclass.initComponent.call(this);
		
		
		var inputPanel = new Ext.form.FormPanel({
    		labelAlign: 'right',
       		frame: true,
       		items: [{
       		 	layout: 'form',
       		 	labelWidth: 60,
       		 	xtype: 'fieldset',
		        title: '<span class="fs_tip">标志 <span class="fs_flag">*</span> 字段为必填项</span>',
	       		items:[{
					layout: 'column',
					items: [{
		       			columnWidth: .5,
		       			layout: 'column',
		       			items: [{
								columnWidth: .6,
								layout: 'form',
								items:[{
									checked: true,
									xtype: 'radio',
					                fieldLabel: '<span class="fs_flag">*</span>&nbsp;类型',
					                boxLabel: '假期',
					                name: 'isHoliday',
					                inputValue: 'Y'
								}]
								
							},{
								columnWidth: .4,
								layout: 'form',
								items:[{
									hideLabel : true,
					                xtype: 'radio',
					                boxLabel: '加班',
					                name: 'isHoliday',
					                inputValue: 'N'
								}]
							}]
		       		}]
				},{
	       			layout: 'column',
		       		items:[{
		       			columnWidth: .99,
		       			layout: 'column',
		       			items: [{
							xtype: 'hidden',
							name: 'id'
						},{
							columnWidth: .5,
							layout: 'form',
							items:[{
								fieldLabel: '<span class="fs_flag">*</span>&nbsp;从',
				       			name: 'from',
				       			xtype: 'datefield',
				       			format: 'Y-m-d',
				       			allowBlank: false,
				       			anchor: '95%'
							}]
			       			
		       		 	},{
		       		 		columnWidth: .5,
							layout: 'form',
							items:[{
								fieldLabel: '<span class="fs_flag">*</span>&nbsp;到',
				       			name: 'to',
				       			xtype: 'datefield',
				       			format: 'Y-m-d',
				       			allowBlank: false,
				       			anchor: '95%'
							}]
		       		 	}]
		       		}]
				},{
		       		 	layout: 'column',
		       		 	items:[{
		       		 		columnWidth: 1,
		       		 		layout: 'form',
		       		 		items: [{
		       		 			fieldLabel: '备注',
			       		 		xtype: 'textarea',
			       		 		name: 'memo',
			       		 		anchor: '97%'
		       		 		}]
		       		 		
		       		 	}]
	       		 }]
       		 }],
       		 buttons: [{
				text: '&nbsp;&nbsp;保存',
				width: 90,
				iconCls: 'icon-middle-save',
				scale: 'medium',
				handler: this.save,
				scope: this
			},{
				text: '&nbsp;&nbsp;关闭窗口',
				width: 90,
				iconCls: 'icon-middle-cancel',
				scale: 'medium',
				handler: function(){
					this.hide();
				},
				scope: this
			}]
    	});
		
    	this.add(inputPanel); 
    	this.detailPanel = inputPanel;
    	
    	this.setDefaultValue();
	},
	//保存
	save: function(){
		
		if(this.detailPanel.form.isValid()){
			this.detailPanel.form.submit({
				url: 'wh-special-time!addSpecialPeriod.action',
				success: function(form, action){
					Ext.Msg.alert('系统提示', '保存非常规工作时间段信息成功');
					this.hide();
					Ext.getCmp('specialTimeGrid').getStore().reload();
				},
				failure: function(){
					Ext.Msg.alert('系统提示', '保存非常规工作日信息失败！');
				},
				params: {
					from: this.detailPanel.form.findField('from').getValue(),
					to: this.detailPanel.form.findField('to').getValue()
				},
				scope: this
			});
		}
	},
	setDefaultValue: function(){
		this.detailPanel.form.findField('from').setValue(new Date);
		this.detailPanel.form.findField('to').setValue(new Date);
	}
});